<%--
    Document   : create fragment for task
    Created on : Mar 10, 2014, 10:54:45 PM
    Author     : Anton Strack
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="csd_content_form">
    <form method="POST" action="${config.getPath()}">
        <div class="form-group">
            <label class="form-control" for="name">Name:</label>
            <input class="form-control" id="name" name="name" autofocus="" type="text"><br />
            <label class="form-control" for="description">Description:</label>
            <p>Describe any details or requirements needed to fulfill the task.</p>
            <textarea class="form-control ckeditor" id="description" name="description" required="" rows="20"></textarea><br />
            <label class="form-control" for="recipient">Task Recipient:</label>
            <p>Select who the task is for.</p>
            <select class="form-control" id="recipient" name="recipient">

                <c:forEach items="${recipients}" var="recipient" >
                    <option value="${recipient.id}">${recipient.name}</option>
                </c:forEach>

                <%-- <option value="2">Writer</option>--%>
            </select><br />
            <label class="form-control" for="action">Task Action:</label>
            <p>Select the primary action of the task.</p>
            <select class="form-control" id="action" name="action">
                <c:forEach items="${actions}" var="action" >
                    <option value="${action.id}">${action.name}</option>
                </c:forEach>
            </select><br />
            <label class="form-control" for="resourceType">Task Resource:</label>
            <p>Select the resource type the task should be preformed on.</p>
            <select class="form-control" id="resourceType" name="resourceType">
                <c:forEach items="${resourceTypes}" var="resourceType" >
                    <option value="${resourceType.id}">${resourceType.name}</option>
                </c:forEach>
            </select><br />
            <c:if test="${not empty taskResourceTypeName}">
                <%-- Only show the resource selection form items if it is populated. If the taskResourceTypeName isn't known then the posts can't be properly populated. --%>
                <fieldset>
                    <legend>Resource Selection</legend>
                    <label class="form-control" for="postId">Task Resource:</label>
                    <p>If the task action is to Create new, leave the selection at "None", otherwise select the correct post.</p>
                    <select class="form-control" id="postId" name="postId">
                        <option value="0">None</option>
                        <c:forEach items="${posts}" var="post" >
                            <c:choose>
                                <c:when test="${selectedId != null && selectedId == post.id}">
                                    <option value="${post.id}" selected="">${post.name}</option>
                                </c:when>
                                <c:otherwise>
                                    <option value="${post.id}">${post.name}</option>
                                </c:otherwise>
                            </c:choose>
                        </c:forEach>
                    </select>
                </fieldset>
            </c:if>

        </div>
        <button class="btn btn-primary" name="formSubmit" id="formSubmit" value="create-task" type="submit">Create Task</button>
    </form>
</div>

